﻿using System.Text.Json;

namespace HDW_Migrate.Extensions;

/// <summary>
/// JSON 扩展方法
/// </summary>
public static class JsonEx
{
    /// <summary>
    /// 转化为 JSON 字符串
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="json"></param>
    /// <returns></returns>
    public static string ToJson<T>(this T json) => JsonSerializer.Serialize(json);

    /// <summary>
    /// 将 JSON 字符串解析为对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="json"></param>
    /// <returns></returns>
    public static T ParseObject<T>(this string json) => JsonSerializer.Deserialize<T>(json);
}
